package com.cheyun.netsalev3.view.defeatdetails

import android.util.Log
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.MoreLayoutDefaultAdapter
import com.cheyun.netsalev3.bean.CallParam
import com.cheyun.netsalev3.bean.MoreLayoutDefaultAdapterParam
import com.cheyun.netsalev3.bean.records.*
import com.cheyun.netsalev3.databinding.HistoricalRecordFragmentBinding
import com.cheyun.netsalev3.utils.BaseFragment
import com.cheyun.netsalev3.viewmodel.ClueDetailsActivityViewModel
import com.jeremyliao.liveeventbus.LiveEventBus

class HistoricalRecordFragment : BaseFragment<HistoricalRecordFragmentBinding>() {
    override fun initContentView(): Int {
        return R.layout.historical_record_fragment
    }

    override fun initViewModel(): ViewModel? {
        activity?.apply {
            return ViewModelProviders.of(this).get(ClueDetailsActivityViewModel::class.java)
        }
        return null
    }


    private lateinit var adapter: MoreLayoutDefaultAdapter

    override fun initView() {
        var listView = ArrayList<MoreLayoutDefaultAdapterParam>()
        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item1, Follow::class))
//        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item2, Transfer::class))
//        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item3, CallParam::class))
//        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item4, HotInfo::class))
//        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item5, PurchaseInfo::class))
//        listView.add(MoreLayoutDefaultAdapterParam(R.layout.historical_record_item6, Reserve::class))

        adapter = MoreLayoutDefaultAdapter(listView, binding.viewModel)
        binding.recyclerView.adapter = adapter
    }

    override fun initData() {
        binding.viewModel?.recordsList?.observe(this, Observer { list ->
            adapter.submitList(list)
        })
    }

    override fun lazyInit() {
        Log.i(TAG,"override lazyinit")
        binding.viewModel?.loadRecord()
    }

    companion object {
        fun newInstance() = HistoricalRecordFragment()
    }

}
